<template>
<div>
    <Form :model="formCustom" :label-width="80">
        <FormItem label="小程序app_id" prop="app_id">
            <Input type="text" v-model="formCustom.app_id" value="formCustom.app_id"></Input>
        </FormItem>
        <FormItem label="小程序app_secret" prop="app_secret" >
            <Input type="text" v-model="formCustom.app_secret" value="formCustom.app_secret"></Input>
        </FormItem>
        <FormItem label="七牛云AK" prop="qiniu_ak">
            <Input type="text" v-model="formCustom.qiniu_ak" value="" ></Input>
        </FormItem>
        <FormItem label="七牛云SK" prop="qiniu_sk">
            <Input type="text" v-model="formCustom.qiniu_sk" value="" ></Input>
        </FormItem>
        <FormItem label="七牛云Bucket" prop="qiniu_bucket">
            <Input type="text" v-model="formCustom.qiniu_bucket" value="" ></Input>
        </FormItem>
        <FormItem label="七牛云BucketUrl" prop="qiniu_bucketurl">
            <Input type="text" v-model="formCustom.qiniu_bucketurl" value="" ></Input>
        </FormItem>
        <FormItem label="聚合ISBNUrl" prop="juhe_url">
            <Input type="text" v-model="formCustom.juhe_url" value="" ></Input>
        </FormItem>
        <FormItem label="聚合juhe_key" prop="juhe_key">
            <Input type="text" v-model="formCustom.juhe_key" value="" ></Input>
        </FormItem>
        <FormItem label="网易云验证码key" prop="wangyi_key">
            <Input type="text" v-model="formCustom.wangyi_key" value="" ></Input>
        </FormItem>
        <FormItem label="网易云验证码seret" prop="wangyi_secret">
            <Input type="text" v-model="formCustom.wangyi_secret" value="" ></Input>
        </FormItem>
        <FormItem label="网易云templateid" prop="wangyi_templateid">
            <Input type="text" v-model="formCustom.wangyi_templateid" value="" ></Input>
        </FormItem>
        <FormItem>
            <Button type="primary" @click="handleSubmit('formCustom')">Submit</Button>
        </FormItem>
    </Form>
</div>
</template>
<script>
    import util from '../libs/util';
    export default {
        created() {
            this.$http.get(util.baseURL+"property/propertyList",)
                    .then(
                        (response)=>{
                            if(response.data.data) {
                              this.process_data(response.data.data);
                            } else {
                               this.$Message.error("暂无配置信息！");
                               return;
                            }
                        },
                        (error)=>{
                            console.log(error);
                        }
                );
               
        },
        data () {
            return {
                formCustom: {
                   app_id : '',
                   app_secret:'',
                   base_collection: ''
                },
            }
        },
        methods: {
            process_data(data) {
                
               for (var i=0; i<data.length; i++) {
                   this.formCustom[data[i].k] = data[i].v;
               }
               
            },
            handleSubmit () {
                //console.log(this.formCustom);
                this.$http.post(util.baseURL+"property/updateProperty",this.formCustom,
                    {emulateJSON: true})
                    .then(
                        (response)=>{
                            if(response.data.data) {
                               this.$Message.info("更新成功！");
                            } else {
                               this.$Message.error("更新失败！");
                            }
                        },
                        (error)=>{
                            console.log(error);
                        }
                );
            },
        }
    }
</script>